
package com.controller.common;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.support.WebBindingInitializer;
import org.springframework.web.context.request.WebRequest;

public class MyWebBindingInitializer implements WebBindingInitializer {

	/**
	 * 调用自定义编辑器针对处理页面上的日期类型是yyyy-MM-dd HH:mm格式的也可以自己定义日期格式 还可以定义别的别的类型编辑器转换
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder, WebRequest request) {

		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		dateFormat.setLenient(true);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
	}
}